<template>
  <view class="wrap">
    <u-form class="login-form" :model="model" :rules="rules" ref="uForm">

      <u-form-item label-width="200" label="预到校日期">
        <u-input :border="border" placeholder="yyyy-mm-dd" v-model="model.check_date" type="text"></u-input>
      </u-form-item>

      <u-form-item label-width="200" label="交通工具">
        <u-input :border="border" placeholder="到校交通工具" v-model="model.vehicle" type="text"></u-input>
      </u-form-item>
      <u-form-item label-width="200" label="预计到校车次">
        <u-input :border="border" placeholder="预计到校车次/车牌号/航班号" v-model="model.vehicle_no" type="text"></u-input>
      </u-form-item>
    </u-form>
    <u-button class="custom-btn" type="primary" @click="submit">提交</u-button>

    <view>
      <u-toast ref="uToast"/>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    let that = this;
    return {
      model: {
        check_date: '',
        vehicle: '',
        vehicle_no: '',
      },
      rules: {},
      border: true,
      check: false,
      selectStatus: 'close',
    };
  },
  onLoad() {

  },
  created() {
    console.log(1)
    this.detail()
  },
  computed: {},
  onReady() {
    this.$refs.uForm.setRules(this.rules);
  },
  methods: {
    detail() {
      this.$u.get('/precheck/detail', {
        student_id: this.vuex_user.id
      }).then(res => {
        console.log(res)
        if(res){
          this.model = res;
        }
      })
    },
    submit() {
      this.model.student_id = this.vuex_user.id
      if (this.model.id) {
        this.$u.put('/precheck/edit', this.model).then(res => {
          this.$refs.uToast.show({
            title: '操作成功',
          })
          this.detail()
        })
      } else {
        this.$u.post('/precheck/add', this.model).then(res => {
          this.$refs.uToast.show({
            title: '操作成功',
          })
          this.detail()
        })
      }
    }
  }
};
</script>

<style scoped lang="scss">
.wrap {
  padding: 30 rpx;
}

.agreement {
  display: flex;
  align-items: center;
  margin: 40 rpx 0;

  .agreement-text {
    padding-left: 8 rpx;
    color: $u-tips-color;
  }
}
.custom-btn{
	margin-top: 40rpx;
}
</style>
